﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entities;
using DAL;
using BUS;
using Utility;

public partial class A_LetsDeal_DoanhNghiep_Image_Add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            HiddenField1.Value = id.ToString();

            Tbl_SanPham_Entities sp = Tbl_SanPham_BUS.GetByID(id);
            tensp.Text = sp.TenSP;
            hyp_back.NavigateUrl = "~/A_LetsDeal-DoanhNghiep/chitietsanpham.aspx?" + Session["tranghientai"].ToString();
        }
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {

        HttpFileCollection hfc = Request.Files;
        for (int i = 0; i < hfc.Count; i++)
        {
            HttpPostedFile hpf = hfc[i];

            if (hpf.ContentLength > 0)
            {
                hpf.SaveAs(Server.MapPath("~/Photos/") + System.IO.Path.GetFileName(hpf.FileName));



                System.Drawing.Image img = System.Drawing.Image.FromFile(
                    Server.MapPath("~/Photos/" + hpf.FileName));

                string tenhinh = DateTime.Now.Ticks.ToString() + hpf.FileName;
                System.Drawing.Image img_xuly = ImageUtility.ProcessPhoto(img, 570, 300);
                ImageUtility.ResizePhotoNoBackground(
                    img, 570, 300, Server.MapPath("~/Photos/Thumbs/"), tenhinh);

                Tbl_ImageSP_Entities imgsp = new Tbl_ImageSP_Entities();
                imgsp.SanPham = int.Parse(HiddenField1.Value);
                imgsp.ImagePath = tenhinh;

                Tbl_ImageSP_BUS.Insert(imgsp);
            }
        }


    }
}

